﻿using System;
using System.Collections.Generic;
using base31.Services.Hub.Helpers;

namespace base31.Services.Hub.Models
{
    /// <summary>
    /// Represents record of the feed from when it has been polled.
    /// This contains everything in a feed except for the entry data. That means any
    /// footers, top-level XML elements, namespace declarations, etc, will be
    /// captured in this entity.
    /// The key name of this entity is a GetHashKeyName() of the topic URL.
    /// </summary>
    public class FeedRecord
    {
        public string Topic { get; set; }
        public string HeaderFooter { get; set; }
        public DateTime LastUpdated { get; set; }
        public string Format { get; set; } //'atom', 'rss', or 'arbitrary'

        //Content-related headers served by the feed's host.
        public string ContentType { get; set; }
        public string LastModified { get; set; }
        public string Etag { get; set; }

        /// <summary>
        /// Creates a key name for a FeedRecord for a topic.
        /// </summary>
        /// <param name="topic">The topic URL for the FeedRecord.</param>
        /// <returns>String containing the key name.</returns>
        public string CreateKeyName(string topic)
        {
            return Helper.GetHashKeyName(topic);
        }

        /// <summary>
        /// Retrieves and/or creates FeedRecord entities for the supplied topics.
        /// </summary>
        /// <param name="topicList">List of topics to retrieve.</param>
        /// <returns>The list of FeedRecords corresponding to the input topic list in the
        /// same order they were supplied.</returns>
        public List<FeedRecord> GetOrCreateAll(List<string> topicList)
        {
            return null;
        }

        /// <summary>
        /// Retrieves a FeedRecord by its topic or creates it if non-existent.
        /// </summary>
        /// <param name="topic">The topic URL to retrieve the FeedRecord for.</param>
        /// <returns>The FeedRecord found for this topic or a new one if it did not already exist.</returns>
        public FeedRecord GetOrCreate(string topic)
        {
            return null;
        }

        /// <summary>
        /// Updates the polling record of this feed.
        /// This method will *not* insert this instance into the Datastore.
        /// </summary>
        /// <param name="headers">Dictionary of response headers from the feed that should be used
        /// to determine how to poll the feed in the future.</param>
        /// <param name="headerFooter">Contents of the feed's XML document minus the entry data.
        /// if not supplied, the old value will remain. Only saved for feeds.</param>
        /// <param name="format">The last parsing format that worked correctly for this feed.
        /// Should be 'rss', 'atom', or 'arbitrary'.</param>
        public void Update(Dictionary<string, string> headers,
                           string headerFooter,
                           string format)
        {
        }

        /// <summary>
        /// Returns the request headers that should be used to pull this feed.
        /// </summary>
        /// <param name="subscriberCount">The number of subscribers this feed has.</param>
        /// <returns>Dictionary of request header values.</returns>
        public Dictionary<string, string> GetRequestHeaders(int subscriberCount)
        {
            return null;
        }
    }
}